package com.ruoyi.web.controller.emergency;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.emergency.domain.EmergencyGoods;
import com.ruoyi.emergency.service.IEmergencyGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应急救援物资Controller
 * 
 * @author hcc
 * @date 2024-11-17
 */
@RestController
@RequestMapping("/control/emergencyGoods")
public class EmergencyGoodsController extends BaseController
{
    @Autowired
    private IEmergencyGoodsService emergencyGoodsService;

    /**
     * 查询应急救援物资列表
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmergencyGoods emergencyGoods)
    {
        startPage();
        List<EmergencyGoods> list = emergencyGoodsService.selectEmergencyGoodsList(emergencyGoods);
        return getDataTable(list);
    }

    /**
     * 导出应急救援物资列表
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyGoods:export')")
    @Log(title = "应急救援物资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmergencyGoods emergencyGoods)
    {
        List<EmergencyGoods> list = emergencyGoodsService.selectEmergencyGoodsList(emergencyGoods);
        ExcelUtil<EmergencyGoods> util = new ExcelUtil<EmergencyGoods>(EmergencyGoods.class);
        util.exportExcel(response, list, "应急救援物资数据");
    }

    /**
     * 获取应急救援物资详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emergencyGoodsService.selectEmergencyGoodsById(id));
    }

    /**
     * 新增应急救援物资
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyGoods:add')")
    @Log(title = "应急救援物资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmergencyGoods emergencyGoods)
    {
        return toAjax(emergencyGoodsService.insertEmergencyGoods(emergencyGoods));
    }

    /**
     * 修改应急救援物资
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyGoods:edit')")
    @Log(title = "应急救援物资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmergencyGoods emergencyGoods)
    {
        return toAjax(emergencyGoodsService.updateEmergencyGoods(emergencyGoods));
    }

    /**
     * 删除应急救援物资
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyGoods:remove')")
    @Log(title = "应急救援物资", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emergencyGoodsService.deleteEmergencyGoodsByIds(ids));
    }
}
